//
// Created by d on 5/20/16.
//

#include "common.h"

PerformanceMeasure::PerformanceMeasure() {
    reset();
}

void PerformanceMeasure::begin() {
    if(!counting){
        counting = true;
        beginTime = clock();
    }
}

void PerformanceMeasure::reset() {
    counting = false;
    counter = 0;
}

void PerformanceMeasure::end() {
    if(counting){
        counting = false;
        endTime = clock();
        counter += (endTime - beginTime);
    }
}

double PerformanceMeasure::getPeriod() {
    clock_t tmp = 0;
    if(counting){
        tmp = clock() - beginTime;
    }
    tmp += counter;
    return ((double) tmp) / CLOCKS_PER_SEC;
}



